
def repeat_string(s, n):
    return s * n


class ShuDuLine:
    def __init__(self, size, tip):
        self.size = size
        self.tip = tip
        self.tipLen = 0
        self.totalStep = 0
        self.path = []
        self.res = []
        self.list = []

    def getLine(self):
        self.tipsToZero()
        self.totalStep = int((len(self.tip) + 1) / 2)
        self.toRand()
        self.resToStr()
        return self.list

    def tipsToZero(self):
        tmpTip = ['']
        for i in self.tip:
            tmpStr = repeat_string('1', i)
            if len(tmpTip) > 1:
                tmpStr = '0' + tmpStr
            tmpTip.append(tmpStr)
            tmpTip.append('')
            self.tipLen += len(tmpStr)

        self.tip = tmpTip

    def resToStr(self):
        for item in self.res:
            for key, value in enumerate(item):
                self.tip[key * 2] = repeat_string('0', value)

            self.list.append(''.join(self.tip))

    def toRand(self):
        tLen = self.size - self.tipLen

        if (self.totalStep - len(self.path) - 1) == 0:
            res = self.path.copy()
            res.append(tLen - sum(self.path))

            self.res.append(res)
            return

        for i in range(0, tLen - sum(self.path) + 1):
            self.path.append(i)
            self.toRand()
            self.path.pop()
